home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / tclX6.4c / dist / tests / string.test < prev    next >
Encoding:
Text File  |  1992-11-07  |  3.2 KB  |  129 lines

  1. #
  2. # string.test
  3. #
  4. # Tests for the cindex, clength, crange, replicate, csubstr, and translit
  5. # commands.
  6. #---------------------------------------------------------------------------
  7. # Copyright 1992 Karl Lehenbauer and Mark Diekhans.
  8. #
  9. # Permission to use, copy, modify, and distribute this software and its
  10. # documentation for any purpose and without fee is hereby granted, provided
  11. # that the above copyright notice appear in all copies.  Karl Lehenbauer and
  12. # Mark Diekhans make no representations about the suitability of this
  13. # software for any purpose.  It is provided "as is" without express or
  14. # implied warranty.
  15. #------------------------------------------------------------------------------
  16. # $Id: string.test,v 2.0 1992/10/16 04:50:12 markd Rel $
  17. #------------------------------------------------------------------------------
  18. #
  19.  
  20. if {[info procs test] != "test"} then {source testlib.tcl}
  21.  
  22. # Test the 'cindex' command.
  23.  
  24. test string-1.1 {cindex tests} {
  25.     cindex ABCDEFG 1
  26. } {B}
  27.  
  28. test string-1.2 {cindex tests} {
  29.     cindex ABCDEFG 3+1
  30. } {E}
  31.  
  32. test string-1.3 {cindex tests} {
  33.     cindex ABCDEFG 3*2
  34. } {G}
  35.  
  36. test string-1.4 {cindex tests} {
  37.     cindex ABCDEFG 7
  38. } {}
  39.  
  40. # Test the 'clength' command.
  41.  
  42. test string-2.1 {clength tests} {
  43.     clength ABCDEFG
  44. } {7}
  45.  
  46. test string-2.2 {clength tests} {
  47.     clength "ABCD XYZ"
  48. } {8}
  49.  
  50. test string-2.3 {clength tests} {
  51.     list [catch {clength} msg] $msg
  52. } {1 {wrong # args: clength string}}
  53.  
  54. # Test the crange command.
  55.  
  56. test string-3.1 {crange tests} {
  57.     crange ABCDEFG 1 3
  58. } {BCD}
  59.  
  60. test string-3.2 {crange tests} {
  61.     crange ABCDEFG 2 end
  62. } {CDEFG}
  63.  
  64. test string-3.3 {crange tests} {
  65.     set foo [replicate ABCD 500]
  66.     crange $foo 25*4 500-1
  67. } [replicate ABCD 100]
  68.  
  69. test string-3.4 {crange tests} {
  70.     list [catch {crange} msg] $msg
  71. } {1 {wrong # args: crange string firstExpr lastExpr}}
  72.  
  73. test string-3.5 {crange tests} {
  74.     crange ABCD 4 1
  75. } {}
  76.  
  77. # Test the 'replicate' command
  78.  
  79. test string-4.1 {replicate tests} {
  80.     replicate AbCd 4
  81. } {AbCdAbCdAbCdAbCd}
  82.  
  83. test string-4.2 {replicate tests} {
  84.     replicate X 1000
  85. } "[replicate X 250][replicate X 250][replicate X 250][replicate X 250]"
  86.  
  87. test string-4.3 {replicate tests} {
  88.     list [catch {replicate X} msg] $msg
  89. } {1 {wrong # args: replicate string countExpr}}
  90.  
  91. # Test the csubstr command.
  92.  
  93. test string-5.1 {csubstr tests} {
  94.     csubstr ABCDEFG 1 2+1
  95. } {BCD}
  96.  
  97. test string-5.2 {csubstr tests} {
  98.     csubstr ABCDEFG 1+1 end
  99. } {CDEFG}
  100.  
  101. test string-5.3 {csubstr tests} {
  102.     set foo [replicate ABCD 500]
  103.     csubstr $foo 25*4 100*4
  104. } [replicate ABCD 100]
  105.  
  106. test string-5.4 {csubstr tests} {
  107.     list [catch {csubstr} msg] $msg
  108. } {1 {wrong # args: csubstr string firstExpr lengthExpr}}
  109.  
  110. test string-5.5 {csubstr tests} {
  111.     csubstr ABCD 4 1
  112. } {}
  113.  
  114. test string-5.6 {translit tests} {
  115.     set str "Captain Midnight Secret Decoder Ring"
  116.     translit {A-MN-Za-mn-z} {N-ZA-Mn-za-m} $str
  117. } {Pncgnva Zvqavtug Frperg Qrpbqre Evat}
  118.  
  119. test string-5.7 {translit tests} {
  120.     set str "Captain Midnight Secret Decoder Ring"
  121.     set str2 [translit {A-MN-Za-mn-z} {N-ZA-Mn-za-m} $str]
  122.     translit {A-MN-Za-mn-z} {N-ZA-Mn-za-m} $str2
  123. } {Captain Midnight Secret Decoder Ring}
  124.  
  125. test string-5.8 {translit tests} {
  126.     list [catch {translit} msg] $msg
  127. } {1 {wrong # args: translit from to string}}
  128.  
  129.